{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# query_list = ['./data/oxford5k_images/hertford_000056.jpg', './data/oxford5k_images/hertford_000056.jpg']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home1/irteam/nashory/workspace/kaggle/google-landmark-challenge/delf/venv/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n"
     ]
    }
   ],
   "source": [
    "import os, sys, time\n",
    "sys.path.append('../')\n",
    "sys.path.append('../train')\n",
    "\n",
    "from PIL import Image\n",
    "from io import BytesIO\n",
    "import matplotlib.image as mpimg\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from train.delf import Delf_V1\n",
    "from feeder import Feeder\n",
    "import matcher\n",
    "\n",
    "def resize_image(image, target_size=800):\n",
    "    def calc_by_ratio(a, b):\n",
    "        return int(a * target_size / float(b))\n",
    "\n",
    "    size = image.size\n",
    "    if size[0] < size[1]:\n",
    "        w = calc_by_ratio(size[0], size[1])\n",
    "        h = target_size\n",
    "    else:\n",
    "        w = target_size\n",
    "        h = calc_by_ratio(size[1], size[0])\n",
    "\n",
    "    image = image.resize((w, h), Image.BILINEAR)\n",
    "    return image\n",
    "\n",
    "\n",
    "def get_and_cache_image(image_path, basewidth=None):\n",
    "    image = Image.open(image_path)\n",
    "    if basewidth is not None:\n",
    "        image = resize_image(image, basewidth)\n",
    "    imgByteArr = BytesIO()\n",
    "    image.save(imgByteArr, format='PNG')\n",
    "    imgByteArr = imgByteArr.getvalue()\n",
    "    return image, imgByteArr\n",
    "\n",
    "\n",
    "def get_result(feeder, query):\n",
    "    pil_image = []\n",
    "    byte_image = []\n",
    "    for _, v in enumerate(query):\n",
    "        pil, byte = get_and_cache_image(v)\n",
    "        pil_image.append(pil)\n",
    "        byte_image.append(byte)\n",
    "\n",
    "    # feed and get output.\n",
    "    outputs = feeder.feed_to_compare(query, pil_image)\n",
    "    \n",
    "    att1 = matcher.get_attention_image_byte(outputs[0]['attention_np_list'])\n",
    "    att2 = matcher.get_attention_image_byte(outputs[1]['attention_np_list'])\n",
    "\n",
    "    side_by_side_comp_img_byte, score = matcher.get_ransac_image_byte(\n",
    "        byte_image[0],\n",
    "        outputs[0]['location_np_list'],\n",
    "        outputs[0]['descriptor_np_list'],\n",
    "        byte_image[1],\n",
    "        outputs[1]['location_np_list'],\n",
    "        outputs[1]['descriptor_np_list'])\n",
    "    print('matching inliner num:', score)\n",
    "    return side_by_side_comp_img_byte, att1, att2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "load DeLF pytorch model...\n",
      "{'arch': 'resnet50', 'expr': 'dummy', 'load_from': '../train/repo/delf_real_clean/keypoint/ckpt/fix.pth.tar', 'ncls': 'dummy', 'stage': 'inference', 'target_layer': 'layer3', 'use_random_gamma_rescale': False}\n",
      "[inference] loading resnet50 pretrained ImageNet weights ... It may take few seconds...\n",
      "deep copied weights from layer \"conv1\" ...\n",
      "deep copied weights from layer \"bn1\" ...\n",
      "deep copied weights from layer \"relu\" ...\n",
      "deep copied weights from layer \"maxpool\" ...\n",
      "deep copied weights from layer \"layer1\" ...\n",
      "deep copied weights from layer \"layer2\" ...\n",
      "deep copied weights from layer \"layer3\" ...\n",
      "deep copied weights from layer \"layer4\" ...\n",
      "loaded weights from module \"base\" ...\n",
      "loaded weights from module \"attn\" ...\n",
      "loaded weights from module \"pool\" ...\n",
      "load model from \"../train/repo/delf_real_clean/keypoint/ckpt/fix.pth.tar\"\n",
      "load PCA parameters...\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from matplotlib.pyplot import imshow\n",
    "\n",
    "feeder_config = {\n",
    "    'GPU_ID': 6,\n",
    "    'IOU_THRES': 0.92,\n",
    "    'ATTN_THRES': 0.37,\n",
    "    'TARGET_LAYER': 'layer3',\n",
    "    'TOP_K': 1000,\n",
    "    'PCA_PARAMETERS_PATH':'./output/pca/delf_real/pca.h5',\n",
    "    'PCA_DIMS':40,\n",
    "    'USE_PCA': True,\n",
    "    'SCALE_LIST': [0.25, 0.3535, 0.5, 0.7071, 1.0, 1.4142, 2.0],\n",
    "    \n",
    "    'LOAD_FROM': '../train/repo/delf_real_clean/keypoint/ckpt/fix.pth.tar',\n",
    "    'ARCH': 'resnet50',\n",
    "    'EXPR': 'dummy',\n",
    "    'TARGET_LAYER': 'layer3',\n",
    "}\n",
    "myfeeder = Feeder(feeder_config)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "pic should be PIL Image or ndarray. Got <class 'list'>",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-3-2802aadbf6dd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m    187\u001b[0m \u001b[0;31m# test 1 (good)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    188\u001b[0m \u001b[0mquery\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m'test/wrongcases/keble/query/keble_4.png'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'test/wrongcases/keble/db/keble_000214.jpg'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 189\u001b[0;31m \u001b[0mresult_image_byte\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0matt1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0matt2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mget_result\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmyfeeder\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mquery\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    190\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m16\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m12\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    191\u001b[0m \u001b[0mresult_image\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mImage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mBytesIO\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mresult_image_byte\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-1-6fd316d85476>\u001b[0m in \u001b[0;36mget_result\u001b[0;34m(feeder, query)\u001b[0m\n\u001b[1;32m     47\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     48\u001b[0m     \u001b[0;31m# feed and get output.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 49\u001b[0;31m     \u001b[0moutputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfeeder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfeed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpil_image\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     51\u001b[0m     \u001b[0matt1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmatcher\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_attention_image_byte\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'attention_np_list'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/nashory/workspace/kaggle/google-landmark-challenge/delf/extract/feeder.py\u001b[0m in \u001b[0;36mfeed\u001b[0;34m(self, pil_image, filename)\u001b[0m\n\u001b[1;32m    137\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    138\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mfeed\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpil_image\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfilename\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'dummy'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 139\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__get_result__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpil_image\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    140\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    141\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mfeed_to_compare\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mquery_path\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpil_image\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/nashory/workspace/kaggle/google-landmark-challenge/delf/extract/feeder.py\u001b[0m in \u001b[0;36m__get_result__\u001b[0;34m(self, path, image)\u001b[0m\n\u001b[1;32m    111\u001b[0m                        image):\n\u001b[1;32m    112\u001b[0m         \u001b[0;31m# load tensor image\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 113\u001b[0;31m         \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__transform__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    114\u001b[0m         \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munsqueeze\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    115\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/nashory/workspace/kaggle/google-landmark-challenge/delf/extract/feeder.py\u001b[0m in \u001b[0;36m__transform__\u001b[0;34m(self, image)\u001b[0m\n\u001b[1;32m     95\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__transform__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mimage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     96\u001b[0m         \u001b[0mtransform\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtransforms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mToTensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 97\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mtransform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     98\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     99\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m__print_result__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/nashory/workspace/kaggle/google-landmark-challenge/delf/venv/lib/python3.6/site-packages/torchvision/transforms/transforms.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, pic)\u001b[0m\n\u001b[1;32m     59\u001b[0m             \u001b[0mTensor\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mConverted\u001b[0m \u001b[0mimage\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     60\u001b[0m         \"\"\"\n\u001b[0;32m---> 61\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_tensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpic\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     62\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     63\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/nashory/workspace/kaggle/google-landmark-challenge/delf/venv/lib/python3.6/site-packages/torchvision/transforms/functional.py\u001b[0m in \u001b[0;36mto_tensor\u001b[0;34m(pic)\u001b[0m\n\u001b[1;32m     42\u001b[0m     \"\"\"\n\u001b[1;32m     43\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_is_pil_image\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpic\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0m_is_numpy_image\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpic\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 44\u001b[0;31m         \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'pic should be PIL Image or ndarray. Got {}'\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpic\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     46\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpic\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mndarray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: pic should be PIL Image or ndarray. Got <class 'list'>"
     ]
    }
   ],
   "source": [
    "\n",
    "'''\n",
    "###### keble_1.png\n",
    "# test 1 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000214.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 2 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000227.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 3 (ok)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000016.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 4 (junk)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000234.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 5 (junk)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000233.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 6 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000199.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 7 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000111.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 8 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_1.png', 'test/wrongcases/keble/db/keble_000036.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "'''\n",
    "\n",
    "'''\n",
    "###### keble_4.png\n",
    "# test 1 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000214.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 2 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000227.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 3 (ok)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000016.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 4 (junk)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000234.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 5 (junk)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000233.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 6 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000199.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 7 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000111.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 8 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000036.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "\n",
    "###### keble_5.png\n",
    "# test 1 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000214.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 2 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000227.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 3 (ok)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000016.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 4 (junk)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000234.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 5 (junk)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000233.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 6 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000199.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 7 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000111.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 8 (arbitrary)\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000036.jpg']\n",
    "result_image_byte, att1, att2 = get_result(feeder_config, delf, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "'''\n",
    "'''\n",
    "# deb\n",
    "query = ['test/wrongcases/keble/query/keble_5.png', 'test/wrongcases/keble/db/keble_000036.jpg']\n",
    "result_image_byte, att1, att2 = get_result(myfeeder, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "'''\n",
    "\n",
    "###### keble_4.png\n",
    "# test 1 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000214.jpg']\n",
    "result_image_byte, att1, att2 = get_result(myfeeder, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n",
    "\n",
    "# test 2 (good)\n",
    "query = ['test/wrongcases/keble/query/keble_4.png', 'test/wrongcases/keble/db/keble_000227.jpg']\n",
    "result_image_byte, att1, att2 = get_result(myfeeder, query)\n",
    "plt.figure(figsize=(16,12))\n",
    "result_image = Image.open(BytesIO(result_image_byte))\n",
    "imshow(np.asarray(result_image), aspect='auto')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "venv"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
